﻿using System;
using System.Collections.Generic;
using System.Deployment.Application;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using ClimateControl.Client.Properties;
using ClimateControl.Infrastructure;
using Microsoft.Practices.Prism.Commands;

namespace ClimateControl.Client.ViewModel
{
    public class SettingsViewModel : BaseViewModel
    {
        #region Fields

        private string originalServiceLocation;

        #endregion Fields

        #region Commands

        private DelegateCommand _saveCommand;
        public DelegateCommand SaveCommand
        {
            get { return _saveCommand; }
            private set { SetAndNotify(ref _saveCommand, value); }
        }

        private DelegateCommand _openLogsCommand;
        public DelegateCommand OpenLogCommand
        {
            get { return _openLogsCommand; }
            private set { SetAndNotify(ref _openLogsCommand, value); }
        }

        #endregion Commands

        #region Constructor

        public SettingsViewModel()
        {
            originalServiceLocation = Settings.Default.ServiceLocation;
            SaveCommand = new DelegateCommand(Save);
            OpenLogCommand = new DelegateCommand(OpenLog);
        }

        #endregion Constructor

        #region Methods

        private void Save()
        {
            Settings.Default.Save();
        }

        private void OpenLog()
        {
            string file = "log.txt";

            if (ApplicationDeployment.IsNetworkDeployed)
                file = Path.Combine(ApplicationDeployment.CurrentDeployment.DataDirectory, file);

            Process.Start(file);
        }

        #endregion Methods
    }
}
